#include "surfacemesh_io_off.h"
#include "surfacemesh_io_helpers.h"

Model* surfacemesh_io_off::open(QString path){
    SurfaceMeshModel* mesh = new SurfaceMeshModel(path);
    /// Checks whether it can do a "special" load first
    bool has_loaded = false;
    if( !has_loaded ) has_loaded |= attempt_read_as_medial_mesh(path,mesh);
    if( !has_loaded ) has_loaded |= attempt_read_as_surfacemesh(path,mesh);
    
    if(!has_loaded){
        delete mesh;
        throw StarlabException("surfacemesh_io_off failed");
    }
    return mesh;
}    
void surfacemesh_io_off::save(QString path, const Model* m){
    const SurfaceMeshModel* mesh = qobject_cast<const SurfaceMeshModel*>( m );
    /// Checks whether it can do a "special" save
    bool has_saved = false;
    if( !has_saved ) has_saved |= attempt_save_as_medial_mesh(path, mesh);
    if( !has_saved ) has_saved |= attempt_save_as_surfacemesh(path, mesh);
}

Q_EXPORT_PLUGIN(surfacemesh_io_off)
 
